﻿using System;
using System.Web;
using System.Web.UI;
using System.Linq;
using Models;


public partial class TagAdd : AdminBase
{
    public int _Id = 0;
    public string _type = "", adminid;

    protected void Page_Load(object sender, EventArgs e)
    {

        Response.CacheControl = "no-cache";

        adminid = Session["adminID"].ToString();

        if (!string.IsNullOrEmpty(Request.Params["ID"]))
        {
            _Id = int.Parse(HttpContext.Current.Request.QueryString["ID"]);
        }

        if (!Page.IsPostBack)
        {

            if (_Id != 0)
            {
                ShowInfo(_Id);
            }
        }
    }

    private void ShowInfo(int _id)
    {

        Entities mydb = new Entities();
        {
            User _lt = mydb.User.First(p => p.UID == _id);
            txtTel.Text = methods.getParent(_lt.UGuid);
            txtUGuid.Text = _lt.UIndirectParentId;
            txtParentUGuid.Text = _lt.UIndirectParentId;

            RadioButtonList2.SelectedValue = _lt.Ustate.ToString();


      
            txtRQ.Text = _lt.UstateEndTime.ToString();
            rptList.DataSource = mydb.U_State_Log.Where(w => w.UGuid == _lt.UGuid).ToList();
            rptList.DataBind();
        }
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Entities mydb = new Entities();
        {
            User Lt = mydb.User.First(p => p.UID == _Id);
            Lt.UIndirectParentId = txtParentUGuid.Text.Trim();
        
            Lt.Ustate = int.Parse(RadioButtonList2.SelectedValue);


                Lt.UstateEndTime = DateTime.Parse(txtRQ.Text.ToString());
   
          

            mydb.SaveChanges();
            Response.Write("<script> var Close=1;</script>");
           _rky.SaveUstatLogs(Lt.UGuid, Convert.ToUInt16(Lt.Ustate),Convert.ToDateTime(Lt.UstateEndTime), adminid, "PC");



        }
    }



}

